<?php
require_once 'Spreadsheet/Excel/Writer.php';
require_once 'Spreadsheet/Excel/Reader.php';

class ExcelReport{
	var $workbook = NULL;
	public function writeExcelInit($file_dir,$file_name){
		if (!file_exists($file_dir)) mkdir($file_dir, 0777);
		$this->workbook = new Spreadsheet_Excel_Writer($file_name);
	}
	
	public function readExcel($file_name){
		$data = new Spreadsheet_Excel_Reader($file_name);
	    $data->setOutputEncoding('GBK');
	    $data->read($file_name);
	    return $data;
	}
	
	public function setWorkSheetColWidth($sheename,$column_width_array=array()){
		$worksheet = & $this->workbook->addWorksheet($sheename);
		foreach($column_width_array as $col_idx=>$width){
			$worksheet->setColumn(0, $col_idx, $width);
		}
	    return $worksheet;
	}
	
	public function writeMultiColumnData($start_rownum,$worksheet,$data_array=array()){
		$row = $start_rownum;
        foreach($data_array as $key => $column_list){
	        foreach($column_list as $col => $value){
	            $worksheet->write($row, $col, $value);
	        }
	        $row++;
	    }
	    return $row;
	}
	
	public function writeSingleColumnData($row,$worksheet,$data_array=array()){
		foreach($data_array as $col => $col_value){
	    	$worksheet->write($row, $col, $col_value);
	    }
	    return 1;
	}
	
	public function close(){
		$this->workbook->close();
	}
}
?>